class Page1 extends egret.Sprite {
	private whole1: egret.Sprite;
	private whole2: egret.Sprite;
	private sp: egret.Shape;
	public constructor() {
		super();
		this.whole1 = new egret.Sprite();
		this.whole2 = new egret.Sprite();

		this.sp = new egret.Shape();
		this.sp.graphics.beginFill(0x000000, 0);
		this.sp.graphics.drawRect(0, 0, 640, 150);
		this.sp.y = 100;




		for (var z = 0; z <= 8; z++) {
			var pic = new egret.Bitmap(RES.getRes("page1pic" + z + "_png"));

			switch (z) {
				case 0: pic.x = 0; pic.y = 0; break;
				case 1: pic.x = 18; pic.y = 12; break;
				case 2: pic.x = 19 + pic.width / 2; pic.y = 341 + pic.height / 2; pic.anchorOffsetX = pic.width / 2; pic.anchorOffsetY = pic.height / 2; break;
				case 3: pic.x = 481 + pic.width / 2; pic.y = 420 + pic.height / 2; pic.anchorOffsetX = pic.width / 2; pic.anchorOffsetY = pic.height / 2; break;
				case 4: pic.x = 464 + pic.width / 2; pic.y = 528 + pic.height / 2; pic.anchorOffsetX = pic.width / 2; pic.anchorOffsetY = pic.height / 2; break;
				case 5: pic.x = pic.width / 2; pic.y = pic.height / 2; pic.anchorOffsetX = pic.width / 2; pic.anchorOffsetY = pic.height / 2; break;
				case 6: pic.x = 461 + pic.width / 2; pic.y =180+ pic.height / 2; pic.anchorOffsetX = pic.width / 2; pic.anchorOffsetY = pic.height / 2; break;
				case 7: pic.x = 440 + pic.width / 2; pic.y = 280 + pic.height / 2; pic.anchorOffsetX = pic.width / 2; pic.anchorOffsetY = pic.height / 2; break;
				case 8: pic.x =28; pic.y = 62;break;
				// case 6:pic.x=0;pic.y=1041;break;
			}
			if (z == 0 || z == 1) {

			}
			else {
				pic.alpha = 0;
			}


			
			if (z >= 5) {
				this.whole2.addChild(pic);
			}
			else {
				this.whole1.addChild(pic);
			}

		}

		this.addChild(this.whole1);
		this.addChild(this.whole2);
		this.addChild(this.sp);
		this.Show();
	}
	public Show() {

		var pic = this.whole1.getChildAt(2);
		setTimeout(function(){
			MusicOnOff2(true);
		},600)
		
		pic.scaleX = 0; pic.scaleY = 0;

		egret.Tween.get(pic).wait(600).to({ alpha: 1, scaleX: 1, scaleY: 1 }, 800, egret.Ease.backOut);
		pic.touchEnabled = true;
		pic.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.TB, this);

		var pic1 = this.whole1.getChildAt(3);
		egret.Tween.get(pic1).wait(1000).to({ alpha: 1 }, 600, egret.Ease.cubicOut);
			egret.Tween.get(pic1, { loop: true }).to({scaleX: 0.8, scaleY: 0.8 }, 800, egret.Ease.cubicOut).to({ scaleX: 1, scaleY: 1 }, 400, egret.Ease.cubicOut);

		// var pic2 = this.whole1.getChildAt(4);
		// pic2.y += 30;
		// egret.Tween.get(pic2).wait(1500).to({ alpha: 1, y: pic2.y - 30 }, 500, egret.Ease.cubicOut);
		// setTimeout(function () {
		// 	egret.Tween.get(pic2, { loop: true }).to({ scaleX: 0.8, scaleY: 0.8 }, 400, egret.Ease.cubicOut).to({ scaleX: 1, scaleY: 1 }, 800, egret.Ease.cubicOut);
		// }, 2000);

	}
	private TB(e: egret.TouchEvent) {
		var This=this;
		this.whole1.getChildAt(2).touchEnabled = false;
		this.whole2.x=this.whole2.width/2;this.whole2.y=this.whole2.height/2;
		this.whole2.anchorOffsetX=this.whole2.width/2;
		this.whole2.anchorOffsetY=this.whole2.height/2;

		this.whole2.scaleX = 0; this.whole2.scaleY = 0;


		egret.Tween.get(this.whole2).to({ alpha: 1, scaleX: 1, scaleY: 1 }, 700, egret.Ease.cubicOut);
		var pic = this.whole2.getChildAt(0);
		egret.Tween.get(pic).to({ alpha: 1}, 700, egret.Ease.cubicOut);

		var pic = this.whole2.getChildAt(3);

		egret.Tween.get(pic).to({ alpha: 1}, 700, egret.Ease.cubicOut);

		var pic1 = this.whole2.getChildAt(1);
		egret.Tween.get(pic1).wait(1000).to({ alpha: 1 }, 600, egret.Ease.cubicOut);
			egret.Tween.get(pic1, { loop: true }).to({ scaleX: 0.8, scaleY: 0.8 }, 800, egret.Ease.cubicOut).to({scaleX: 1, scaleY: 1 }, 400, egret.Ease.cubicOut);

		// var pic2 = this.whole2.getChildAt(2);
		// pic2.y += 30;
		// egret.Tween.get(pic2).wait(1500).to({ alpha: 1, y: pic2.y - 30 }, 500, egret.Ease.cubicOut);
		// setTimeout(function () {
		// 	egret.Tween.get(pic2, { loop: true }).to({ scaleX: 0.8, scaleY: 0.8 }, 400, egret.Ease.cubicOut).to({ scaleX: 1, scaleY: 1 }, 800, egret.Ease.cubicOut);
		// }, 2000);
		setTimeout(function(){
			This.sp.touchEnabled=true;
			This.sp.addEventListener(egret.TouchEvent.TOUCH_BEGIN,This.TBB,This);
		},1000)
	}
	private TBB(e:egret.TouchEvent){
			this.sp.touchEnabled=false;
			this.sp.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.TBB,this);
			// egret.Tween.get(this).to({x:-100},700,egret.Ease.cubicOut);
			egret.Tween.get(this.whole2.getChildAt(3)).to({ alpha: 1}, 400, egret.Ease.cubicOut);
			// setTimeout(function(){
				GoEvent.msg.dispatchEvent(new GoEvent("ChangePage","2"));
			// },400)
	}

}
declare function MusicOnOff2(bl)